/*
 * Copyright (C) 2021 Huawei Device Co., Ltd.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.bytedance.scenedemo.animatiom.sipnner;

import ohos.agp.components.Component;
import ohos.agp.render.render3d.math.Quaternion;
import ohos.app.Context;

import java.util.List;

/**
 * Popup.
 *
 * @since 2021-06-17
 */
public class Popup {
    private static final int ANIMATION_DURATION = 100;
    private static final int SHADOW_BG_COLOR = 0x0000007F;
    /**
     * longClickPoint
     */
    private static Quaternion longClickPoint = null;

    private Popup() {
    }

    public static int getShadowBgColor() {
        return SHADOW_BG_COLOR;
    }



    public static int getAnimationDuration() {
        return ANIMATION_DURATION;
    }

    /**
     * Builder
     *
     * @since 2021-06-17
     */
    public static class Builder {
        private final PopupInfo popupInfo = new PopupInfo();
        private Context context;

        /**
         * Builder
         *
         * @param context Context
         */
        public Builder(Context context) {
            this.context = context;
        }

        /**
         * popupType
         *
         * @param popupType PopupType
         * @return Builder
         */
        public Builder popupType(PopupType popupType) {
            this.popupInfo.setPopupType(popupType);
            return this;
        }

        /**
         * 弹窗是否有半透明背景遮罩，默认是true
         *
         * @param hasShadowBg 弹窗是否有半透明背景遮罩，暂未实现
         * @return Builder构造器对象
         */
        public Builder hasShadowBg(Boolean hasShadowBg) {
            this.popupInfo.setHasShadowBg(hasShadowBg);
            return this;
        }

        /**
         * 设置弹窗依附的View，Attach弹窗必须设置这个
         *
         * @param atView 弹窗依附的控件
         * @return Builder构造器对象
         */
        public Builder atView(Component atView) {
            this.popupInfo.setAtView(atView);
            return this;
        }

        /**
         * 是否在弹窗消失后就立即释放资源，杜绝内存泄漏，仅仅适用于弹窗只用一次的场景，默认为false。
         * 如果你的弹窗对象需是复用的，千万不要开启这个设置
         *
         * @param isDestroyOnDismiss 是否在弹窗消失后就立即释放资源
         * @return Builder构造器对象
         */
        public Builder isDestroyOnDismiss(boolean isDestroyOnDismiss) {
            this.popupInfo.setDestroyOnDismiss(isDestroyOnDismiss);
            return this;
        }

        /**
         * 显示依附于某View的列表，必须调用atView()方法，指定依附的View
         *
         * @param data           显示的文本数据
         * @param selectListener 选中条目的监听器
         * @return 显示依附于某View的列表，必须调用atView()方法，指定依附的View
         */
        public AttachListPopupView asAttachList(List<String> data, OnSelectListener selectListener) {
            popupType(PopupType.AttachView);
            AttachListPopupView popupView = new AttachListPopupView(this.context, popupInfo)
                    .setStringData(data)
                    .setOnSelectListener(selectListener);
            return popupView;
        }
    }

    public static Quaternion getLongClickPoint() {
        return longClickPoint;
    }

    public static void setLongClickPoint(Quaternion longClickPoint) {
        Popup.longClickPoint = longClickPoint;
    }
}
